<template>
  <uni-nav-bar
    backgroundColor="#fff"
    @clickLeft="customLeft"
    fixed
    statusBar
    :left-icon="showLeft ? leftIcon : ''"
    :border="false"
    v-bind="attrs" />
</template>

<script setup lang="ts">
import { useAttrs } from 'vue';
const attrs = useAttrs(); // 透传过来的属性及方法
interface PropsType {
  leftIcon?: string;
  showLeft?: boolean;
  backUrl?: string;
}

// 接收props
let props = withDefaults(defineProps<PropsType>(), {
  leftIcon: 'left',
  showLeft: true,
  backUrl: '',
});

// 返回 【click】
let customLeft = () => {
  if (!props.showLeft || !props.leftIcon) return;
  //获取路由
  let routes = getCurrentPages();
  // 如果有指定返回地址
  if (props.backUrl) {
    uni.reLaunch({
      url: props.backUrl,
    });
    return;
  }
  // 说明不是刷新，分享等单个路由。
  if (routes && routes.length > 1) return uni.navigateBack();
  uni.reLaunch({
    url: '/pages/index/index',
  });
};
</script>

<style lang="scss"></style>
